package com.tp1.log121.formes;

import java.awt.Color;
import java.awt.Graphics2D;

import com.tp1.log121.main.ApplicationSupport;
import com.tp1.log121.main.ChaineDecortiquee;

public class Rectangle extends Forme {

	private final Color COULEUR_CARRE = Color.RED;
	private final Color COULEUR_RECTANGLE = Color.ORANGE;

	private int x;
	private int y;
	private int l;
	private int h;

	public Rectangle(ChaineDecortiquee cd) {
		super(cd);
		this.l = Integer.parseInt(informations[2])
				- Integer.parseInt(informations[0]);
		this.h = Integer.parseInt(informations[3])
				- Integer.parseInt(informations[1]);

		if (nomForme.equals(FormesNoms.RECTANGLE)) {
			couleur = COULEUR_RECTANGLE;
			priorite = Integer.parseInt(ApplicationSupport
					.getResource("app.frame.shape.priority.rectangle"));
		} else {
			couleur = COULEUR_CARRE;
			priorite = Integer.parseInt(ApplicationSupport
					.getResource("app.frame.shape.priority.square"));
		}
	}

	@Override
	public void dessinerFormeOriginales(Graphics2D g2d) {
		x = Integer.parseInt(informations[0]);
		y = Integer.parseInt(informations[1]);

		dessinerForme(g2d);
	}

	@Override
	public void dessinerFormeModifiees(Graphics2D g2d, int x, int y) {
		this.x = x;
		this.y = y;

		dessinerForme(g2d);
	}

	@Override
	public int getAire() {
		return l * h;
	}

	@Override
	public int getDistanceMaximale() {
		if (Integer.valueOf(l).compareTo(Integer.valueOf(h)) == 1) {
			return l;
		} else {
			return h;
		}

	}

	@Override
	public int getLargeur() {
		return l;
	}

	@Override
	public int getHauteur() {
		return h;
	}

	@Override
	protected void dessinerForme(Graphics2D g2d) {
		g2d.setColor(Color.BLACK);
		g2d.drawRect(x, y, l, h);
		g2d.setColor(couleur);
		g2d.fillRect(x + 1, y + 1, l - 1, h - 1);

	}
}
